<template>
  <div>
    <el-card style="width: 100%">
      <table-list
        ref="tableList"
        :fields="tableDataColumn"
        :pagination="true"
        :searchFunc="getUserProductList"
        :searchDefault="searchConditions"
        border></table-list>
    </el-card>
  </div>
</template>
<script>
import { getUserProductList, getList as getUserList } from '@/api/user';
import { getList as getProductList } from '@/api/product';
import TableList from '@/components/TableList/index';
export default {
  name: 'showUserProduct',
  props: {
    userId: {
      type: [String, Number],
      default: 0,
    },
  },
  components: {
    TableList,
  },
  data() {
    return {
      getUserProductList,
      tableDataColumn: [
        {
          prop: 'id',
          searchName: 'id',
          label: 'ID',
          minWidth: '60',
          searchType: 'input',
          exact: true,
        },
        {
          prop: 'product_key',
          searchName: 'product_key',
          label: '序列号',
          minWidth: '80',
          searchType: 'input',
          exact: true,
        },
        {
          prop: 'user.nick_name',
          searchName: 'user_id',
          label: '用户',
          minWidth: '120',
          searchType: 'remoteSelect',
          searchAction: getUserList,
          searchKey: 'id',
          searchLabel: 'name',
          exact: true,
        },
        {
          prop: 'product.product_name',
          searchName: 'product_id',
          label: '产品名称',
          minWidth: '180',
          searchType: 'remoteSelect',
          searchAction: getProductList,
          searchKey: 'id',
          searchLabel: 'product_name',
          exact: true,
        },
        {
          prop: 'product.product_no',
          searchName: 'product_id',
          label: '产品编号',
          minWidth: '180',
          searchType: 'remoteSelect',
          searchAction: getProductList,
          searchKey: 'id',
          searchLabel: 'product_no',
          exact: true,
        },
        {
          prop: 'unit_price',
          searchName: 'unit_price',
          label: '单价',
          minWidth: '100',
          searchType: 'input',
          exact: true,
        },
        {
          prop: 'request_number',
          searchName: 'request_number',
          label: '请求数量',
          minWidth: '100',
        },
        {
          prop: 'charge_number',
          searchName: 'charge_number',
          label: '扣费数量',
          minWidth: '100',
        },
        {
          prop: 'remark',
          searchName: 'remark',
          label: '备注',
          minWidth: '160',
          searchType: 'input',
        },
        {
          prop: 'created_at',
          searchName: 'created_at',
          label: '创建时间',
          minWidth: '180',
          searchType: 'dateTime',
        },
      ],
    };
  },
  computed: {
    searchConditions() {
      return {
        user_id: this.userId,
      };
    },
  },
};
</script>